package com.eirikb.gwt.chat.server;

import java.util.ArrayList;

/**
 *
 * @author eirikb
 */
public class User {

    private boolean pong;
    private ArrayList<Message> chat;
    private ArrayList<String> joins;
    private ArrayList<String> leaves;
    private long hash;

    public User(long hash) {
        this.hash = hash;
        pong = true;
        chat = new ArrayList<Message>();
        joins = new ArrayList<String>();
        leaves = new ArrayList<String>();
    }

    public void pong() {
        pong = true;
    }

    public boolean ping() {
        boolean all = pong;
        pong = false;
        return all;
    }

    public void add(Message chat) {
        this.chat.add(chat);
    }

    public void addJoin(String nick) {
        joins.add(nick);
    }

    public void addLeave(String nick) {
        leaves.add(nick);
    }

    public String[] getJoins() {
        String[] all = joins.toArray(new String[joins.size()]);
        joins.clear();
        return all;
    }

    public String[] getLeaves() {
        String[] all = leaves.toArray(new String[leaves.size()]);
        leaves.clear();
        return all;
    }

    public Message[] getChat() {
        Message[] all = chat.toArray(new Message[chat.size()]);
        chat.clear();
        return all;
    }

    public boolean checkHash(long hash) {
        return this.hash == hash;
    }

    public long getHash() {
        return hash;
    }
}
